<?php
require_once '../libs/app.config.php';
session_start();
if($_SESSION['LoginId'] == false){
	header("Location:login.php");
}

if($_POST['submit']){if($_GET['act']=='add'){

	$add=array("admin_name"=>$name,
			   "admin_email"=>$email,
			   "password"=>md5($pwd1),
			   "group_id"=>$group);

	 $result=$tpm->insert("admin_user",$add);
	 if($result>0)
	 echo "<script>alert('Add successfully');location.href=('admin_list.php');</script>";


}
}

if($_GET['id']==""){
$sql="select * from admin_group";
$query=$tpm->query($sql);
while($row=$tpm->fetch_array($query))
{{
	$group[]=$row;
}} $sqls="select group_id,admin_name,admin_email from admin_user where id='".$_GET['id']."'";
  $query=$tpm->query($sqls);
  $rows=$tpm->fetch_array($query);

if($id!="")

$sql="select * from admin_group";
$query=$tpm->query($sql);
$str="";
while($row=$tpm->fetch_array($query))
{
	if($row['id']==$rows['group_id'])
	{
		$str.="<option value=".$row['id']." selected>".$row['group_name']."</option>";
	}
	else
	{
		$str.="<option value=".$row['id'].">".$row['group_name']."</option>";
	}
}
}




require_once(INCLUDE_PATH.'template.inc.php');  //模板类及对象$tpl的加载
$tpl->assign("rows",$rows);
$tpl->assign("group",$group);
$tpl->assign("id",$id);
$tpl->assign("str",$str);
$tpl->display("admin_add.html");
?>

